#include "SQLConstraintImpl.h"

SQLConstraintImpl::SQLConstraintImpl()
{
  hints = std::make_shared<std::list<SQLCommentHint_ptr>>();
}

void SQLConstraintImpl::cloneTo(SQLConstraintImpl_ptr x)
{
  if (getName() != NULL)
  {
    x->setName(getName());
  }

  x->enable = enable;
  x->validate = validate;
  x->rely = rely;
}

SQLCommentHint_list_ptr SQLConstraintImpl::getHints()
{
  return hints;
}

void SQLConstraintImpl::setHints(SQLCommentHint_list_ptr hints)
{
  this->hints = hints;
}

SQLName_ptr SQLConstraintImpl::getName()
{
  return name;
}

void SQLConstraintImpl::setName(SQLName_ptr name)
{
  if (name != NULL)
  {
    name->setParent(SharedObject(SQLConstraintImpl));
  }
  this->name = name;
}

void SQLConstraintImpl::setName(string_ptr  name)
{
  this->setName(SQLIdentifierExpr_ptr(new SQLIdentifierExpr((name))));
}

BOOL_ptr SQLConstraintImpl::getEnable()
{
  return enable;
}

void SQLConstraintImpl::setEnable(BOOL_ptr enable)
{
  this->enable = enable;
}

void SQLConstraintImpl::cloneTo(SQLConstraint_ptr x)
{
  if (getName() != NULL)
  {
    x->setName(getName());
  }
}

BOOL_ptr SQLConstraintImpl::getValidate()
{
  return validate;
}

void SQLConstraintImpl::setValidate(BOOL_ptr validate)
{
  this->validate = validate;
}

BOOL_ptr SQLConstraintImpl::getRely()
{
  return rely;
}

void SQLConstraintImpl::setRely(BOOL_ptr rely)
{
  this->rely = rely;
}

DbType_ptr  SQLConstraintImpl::getDbType()
{
  return dbType;
}

void SQLConstraintImpl::setDbType(DbType_ptr  dbType)
{
  this->dbType = dbType;
}

SQLExpr_ptr SQLConstraintImpl::getComment()
{
  return comment;
}

void SQLConstraintImpl::setComment(SQLExpr_ptr x)
{
  if (x != NULL)
  {
    x->setParent(SharedObject(SQLConstraintImpl));
  }
  this->comment = x;
}

void SQLConstraintImpl::simplify()
{
  // if (getName() instanceof SQLIdentifierExpr) {
  //     SQLIdentifierExpr identExpr = (SQLIdentifierExpr) getName();
  //     string_ptr  columnName = identExpr->getName();

  //     string_ptr  normalized = SQLUtils->normalize(columnName, dbType);
  //     if (columnName != normalized) {
  //         this->setName(normalized);
  //     }
  // }
}

BOOL_ptr SQLConstraintImpl::replace(SQLExpr_ptr expr, SQLExpr_ptr target)
{
  if (getName() == expr)
  {
    setName(std::dynamic_pointer_cast<SQLName>(target));
    return BOOL::TRUE;
  }

  if (getComment() == expr)
  {
    setComment(target);
    return BOOL::TRUE;
  }
  return BOOL::FALSE;
}
